﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;


namespace excel003
{
    public partial class MainWindow : Form
    {
        /// <summary>
        /// Data Member
        /// </summary>
        private string _filename;
        private XPaidAndUnpaidParser _xPaidAndUnPaidParser;


        public MainWindow()
        {
            InitializeComponent();
        }
        /// <summary>
        /// Initialize all the data member
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainWindow_Load(object sender, EventArgs e)
        {
            _xPaidAndUnPaidParser = new XPaidAndUnpaidParser();
            _filename = null;
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            hAbout hAboutBox = new hAbout();
            hAboutBox.ShowDialog();
        }

        private void BrowseButton_Click(object sender, EventArgs e)
        {
            Stream myStream = null;
            OpenFileDialog openExcelDialog = new OpenFileDialog();

            openExcelDialog.InitialDirectory = "c:\\";
            openExcelDialog.Filter = "excel files (*.xls)|*.xls";
            openExcelDialog.FilterIndex = 2; // what's this?
            openExcelDialog.RestoreDirectory = true;  // restore?

            if (openExcelDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openExcelDialog.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            _filename = openExcelDialog.FileName;
                            textboxFile.Text = _filename;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Cannot Open File : " + ex.Message);
                    return;
                }

            }
        }

        private void AnalysisButton_Click(object sender, EventArgs e)
        {
            if (_filename != null)
            {
                _xPaidAndUnPaidParser.excelParser(_filename);
            }
            else
            {
                MessageBox.Show("Error: no input file, Please Load Excel File First");
            }
        }



    }
}
